<?
class healthcenter extends module{

    // Author: Herman Tolentino MD
    // CHITS Project 2004

    function healthcenter() {
        //
        // do not forget to update version
        //
        $this->author = 'Herman Tolentino MD';
        $this->version = "0.8-".date("Y-m-d");
        $this->module = "healthcenter";
        $this->description = "CHITS Module - Health Center";
    }

    // --------------- STANDARD MODULE FUNCTIONS ------------------

    function init_deps() {
    //
    // insert dependencies in module_dependencies
    //
        module::set_dep($this->module, "module");
        module::set_dep($this->module, "ptgroup");
        module::set_dep($this->module, "patient");
        module::set_dep($this->module, "barangay");
        module::set_dep($this->module, "family");
        module::set_dep($this->module, "icd10");
        module::set_dep($this->module, "vaccine");
        module::set_dep($this->module, "complaint");
        module::set_dep($this->module, "wtforage");
        module::set_dep($this->module, "lab");

    }

    function init_lang() {
    //
    // insert necessary language directives
    // NOTES:
    //

        module::set_lang("LBL_PTGROUP", "english", "PATIENT GROUP", "Y");
        module::set_lang("FTITLE_CONSULT_MODULE", "english", "CONSULT MODULE FORM", "Y");
        module::set_lang("LBL_CONSULT_MODULE", "english", "CONSULT MODULE", "Y");
        module::set_lang("FTITLE_LOADED_CONSULT_MODULES", "english", "LOADED CONSULT MODULE", "Y");
        module::set_lang("LBL_BLOODPRESSURE", "english", "BLOOD PRESSURE", "Y");
        module::set_lang("LBL_HEARTRATE", "english", "HEART RATE", "Y");
        module::set_lang("LBL_RESPRATE", "english", "RESPIRATORY RATE", "Y");
        module::set_lang("LBL_WEIGHT", "english", "BODY WEIGHT (KG)", "Y");
        module::set_lang("LBL_WEIGHT", "english", "BODY WEIGHT (KG)", "Y");
        module::set_lang("LBL_BODYTEMP", "english", "BODY TEMP (C)", "Y");
        module::set_lang("LBL_VISIT_TYPE", "english", "VISIT TYPE", "Y");
        module::set_lang("INSTR_CORRECT_VALUES", "english", "INSTRUCTIONS: Fill in the form below with correct values:", "Y");
        module::set_lang("FTITLE_VITAL_SIGNS_RECORD", "english", "VITAL SIGNS RECORD", "Y");
        module::set_lang("FTITLE_PREVIOUS_VISITS", "english", "PREVIOUS VISITS:", "Y");
        module::set_lang("LBL_FAMILY_NUMBER", "english", "FAMILY NUMBER:", "Y");
        module::set_lang("LBL_TOTAL_VISITS", "english", "TOTAL VISITS:", "Y");
        module::set_lang("LBL_LAST_VISIT", "english", "LAST VISIT:", "Y");
        module::set_lang("LBL_ELAPSED_TIME", "english", "ELAPSED TIME:", "Y");
        module::set_lang("BTN_END_CONSULT", "english", "END CONSULT", "Y");
        module::set_lang("FTITLE_PATIENT_GROUP", "english", "PATIENT GROUP:", "Y");
        module::set_lang("FTITLE_CONSULT_COMPLAINT", "english", "CONSULT COMPLAINT:", "Y");
        module::set_lang("BTN_SAVE_DETAILS", "english", "Save Details", "Y");
        module::set_lang("MENU_VISIT_DETAILS", "english", "VISIT DETAILS", "Y");
        module::set_lang("MENU_APPTS", "english", "APPTS", "Y");
        module::set_lang("MENU_VITAL_SIGNS", "english", "VITAL SIGNS", "Y");
        module::set_lang("MENU_LABS", "english", "LABS", "Y");
        module::set_lang("MENU_NOTES", "english", "NOTES", "Y");
        module::set_lang("MENU_PROFILES", "english", "PROFILES", "Y");
        module::set_lang("MENU_MODULES", "english", "MODULES", "Y");
        module::set_lang("FTITLE_CONSULT_COMPLAINTS", "english", "CONSULT COMPLAINTS", "Y");
        module::set_lang("FTITLE_LAB_REQUEST", "english", "LAB REQUEST FORM", "Y");
        module::set_lang("LBL_LABS", "english", "LAB EXAMS", "Y");

    }

    function init_stats() {
    }

    function init_help() {
    }

    function init_menu() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
        }

        // menu entries
        // parameters:
        // module::set_menu(MODULE_NAME, MENU_CAPTION, MENU_CAT, MODULE_METHOD)
        //
        module::set_menu($this->module, "Today\'s Patients", "CONSULTS", "_consult");
        module::set_menu($this->module, "Modules", "CONSULTS", "_modules");
        module::set_menu($this->module, "Consult Stats", "STATS", "_consult_stats");

        // put in more details
        module::set_detail($this->description, $this->version, $this->author, $this->module);

    }

    function init_sql() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
        }

        module::execsql("CREATE TABLE `m_lib_healthcenter` (".
               "`healthcenter_id` varchar(25) NOT NULL default '',".
               "`healthcenter_name` varchar(100) NOT NULL default '',".
               "`area_code` varchar(10) NOT NULL default '',".
               "PRIMARY KEY  (`healthcenter_id`)".
               ") TYPE=InnoDB;");

        module::execsql("CREATE TABLE `m_consult` (".
               "`consult_id` float NOT NULL auto_increment,".
               "`ptgroup_id` varchar(10) NOT NULL default '0',".
               "`patient_id` int(11) NOT NULL default '0',".
               "`healthcenter_id` varchar(25) NOT NULL default '0',".
               "`consult_timestamp` timestamp(14) NOT NULL,".
               "`consult_end` timestamp(14) NOT NULL default '00000000000000',".
               "`consult_complaint` varchar(255) NOT NULL default '',".
               "`consult_visit_type` char(1) NOT NULL default '',".
               "PRIMARY KEY  (`consult_id`)".
               ") TYPE=InnoDB; ");

        module::execsql("CREATE TABLE `m_consult` (".
            "`consult_id` float NOT NULL auto_increment,".
            "`patient_id` int(11) NOT NULL default '0',".
            "`user_id` int(11) NOT NULL default '0',".
            "`healthcenter_id` varchar(25) NOT NULL default '0',".
            "`consult_timestamp` timestamp(14) NOT NULL,".
            "`consult_end` timestamp(14) NOT NULL default '00000000000000',".
            "`consult_visit_type` char(1) NOT NULL default '',".
            "PRIMARY KEY  (`consult_id`),".
            "KEY `key_user` (`user_id`),".
            "KEY `key_patient` (`patient_id`)".
            ") TYPE=InnoDB; ");

        module::execsql("CREATE TABLE `m_consult_vitals` (".
               "`consult_id` float NOT NULL default '0',".
               "`vitals_timestamp` timestamp(14) NOT NULL,".
               "`patient_id` float NOT NULL default '0',".
               "`user_id` int(11) NOT NULL default '0',".
               "`vitals_weight` float NOT NULL default '0',".
               "`vitals_temp` float NOT NULL default '0',".
               "`vitals_systolic` int(11) NOT NULL default '0',".
               "`vitals_diastolic` int(11) NOT NULL default '0',".
               "`vitals_heartrate` int(11) NOT NULL default '0',".
               "`vitals_resprate` int(11) NOT NULL default '0',".
               "PRIMARY KEY  (`consult_id`,`vitals_timestamp`),".
               "KEY `fk_patient_id` (`patient_id`)".
               ") TYPE=InnoDB;");

        module::execsql("CREATE TABLE `m_consult_diagnosis` (".
               "`consult_id` float NOT NULL default '0',".
               "`diagnosis_code` varchar(12) NOT NULL default '',".
               "`diagnosis_text` text, ".
               "PRIMARY KEY  (`diagnosis_code`,`consult_id`)".
               ") TYPE=InnoDB;");

        module::execsql("CREATE TABLE `m_consult_ptgroup` (".
               "`ptgroup_id` varchar(10) NOT NULL default '',".
               "`consult_id` float NOT NULL default '0',".
               "`ptgroup_timestamp` timestamp(14) NOT NULL,".
               "`user_id` int(11) NOT NULL default '0',".
               "PRIMARY KEY  (`consult_id`,`ptgroup_id`)".
               ") TYPE=InnoDB;");

        module::execsql("CREATE TABLE `m_consult_complaint` (".
               "`consult_id` float NOT NULL default '0',".
               "`complaint_id` varchar(10) NOT NULL default '',".
               "`user_id` int(11) NOT NULL default '0',".
               "`complaint_timestamp` timestamp(14) NOT NULL,".
               "PRIMARY KEY  (`consult_id`,`complaint_id`)".
               ") TYPE=InnoDB;");

        module::execsql("CREATE TABLE `m_consult_appointments` (".
            "`visit_date` date NOT NULL default '0000-00-00',".
            "`consult_id` float NOT NULL default '0',".
            "`schedule_timestamp` timestamp(14) NOT NULL,".
            "`user_id` float NOT NULL default '0',".
            "`patient_id` float NOT NULL default '0',".
            "`patient_group` varchar(10) NOT NULL default '',".
            "`visit_done` char(1) NOT NULL default '',".
            " PRIMARY KEY  (`visit_date`,`patient_id`,`patient_group`)".
            ") TYPE=InnoDB; ");

        module::execsql("CREATE TABLE `m_healthcenter_modules` (".
               "`module_id` varchar(25) NOT NULL default '',".
               "PRIMARY KEY  (`module_id`)".
               ") TYPE=InnoDB;");

    }

    function drop_tables() {
        module::execsql("DROP TABLE `m_lib_healthcenter`;");
        module::execsql("DROP TABLE `m_consult`;");
        module::execsql("DROP TABLE `m_consult_vitals`;");
        module::execsql("DROP TABLE `m_consult_diagnosis`;");
        module::execsql("DROP TABLE `m_consult_ptgroup`;");
        module::execsql("DROP TABLE `m_consult_complaint`;");
        module::execsql("DROP TABLE `m_healthcenter_modules`;");
    }

    // --------------- CUSTOM MODULE FUNCTIONS ------------------

    function _healthcenter() {
    }

    function get_mothers_name() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $consult_id = $arg_list[0];
        }
        $sql = "select p.patient_mother from m_patient p, m_consult c ".
               "where c.patient_id = p.patient_id and c.consult_id = '$consult_id'";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                list($mother) = mysql_fetch_array($result);
                return $mother;
            }
        }
    }

    function form_selectmodule() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            //print_r($arg_list);
        }
        print "<table width='300'>";
        print "<form action = '".$_SERVER["SELF"]."?page=".$get_vars["page"]."&menu_id=$menu_id' name='form_module' method='post'>";
        print "<tr valign='top'><td>";
        print "<span class='consult'>".FTITLE_CONSULT_MODULE."</span><br/><br/>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<b>NOTE: You are adding a sub-module to the health center module. Please read instructions for module integration.</b><br/><br/>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_CONSULT_MODULE."</span><br> ";
        print module::show_modules($module["module_id"]?$module["module_id"]:$post_vars["module"]);
        print "<br/><br/></td></tr>";
        print "<tr><td>";
        print "<br><input type='submit' value = 'Add Module' class='textbox' name='submitmodule' style='border: 1px solid #000000'><br> ";
        print "</td></tr>";
        print "</form>";
        print "</table><br>";
    }

    function process_module() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        if ($get_vars["delete_id"]) {
            $sql = "delete from m_healthcenter_modules where module_id = '".$post_vars["module_id"]."'";
            $result = mysql_query($sql);
        }
        switch ($post_vars["submitmodule"]) {
        case "Add Module":
            if ($post_vars["module"]) {
                $sql = "insert into m_healthcenter_modules (module_id) ".
                       "values ('".$post_vars["module"]."')";
                $result = mysql_query($sql);
            }
            break;
        }
    }

    function display_modules() {
        if (func_num_args()) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
        }
        print "<table width='620'>";
        print "<tr valign='top'><td colspan='3'>";
        print "<span class='module'>".FTITLE_LOADED_CONSULT_MODULES."</span><br><br>";
        print "</td></tr>";
        print "<tr valign='top'><td colspan='4'>";
        print "<b>Click on module name to see details (and source code).</b><br><br>";
        print "</td></tr>";
        print "<tr valign='top'><td><b>ID</b></td><td><b>NAME</b></td><td><b>INIT STATUS</b></td><td><b>VERSION</b></td><td><b>DESCRIPTION</b></td></tr>";
        $sql = "select c.module_id, m.module_name, m.module_init, m.module_version, m.module_desc ".
               "from modules m, m_healthcenter_modules c ".
               "where m.module_id = c.module_id order by m.module_name";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                while (list($id, $name, $init, $version, $desc) = mysql_fetch_array($result)) {
                    print "<tr class='tinylight' valign='top'><td>$id</td><td><a href='".$_SERVER["SELF"]."?page=MODULES&module_id=$id'>$name</a></td><td>".($init=="N"?"No <a href='".$_SERVER["PHP_SELF"]."?page=MODULES&method=INIT'>[<b>activate</b>]</a>":"Yes")."</td><td>$version</td><td>".($desc?"$desc":"<font color='red'>empty</font>")."</td></tr>";
                }
            } else {
                print "<tr valign='top'><td colspan='4'>";
                print "<font color='red'>No modules loaded.</font><br>";
                print "</td></tr>";
            }
        }
        print "</table><br>";
    }

    function _modules() {
        if (func_num_args()) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            print_r($arg_list);
        }
        if ($post_vars["submitmodule"]) {
            $this->process_module($menu_id, $post_vars, $get_vars);
        }
        $this->display_modules($menu_id, $post_vars, $get_vars);
        $this->form_selectmodule($menu_id, $post_vars, $get_vars);
    }


    function _consultmodules() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        if ($get_vars["group"] || $get_vars["complaint"]) {
            // determine module name
            if ($get_vars["group"]) {
                $module_id = ptgroup::module_name($get_vars["group"]);
            }
            if ($get_vars["complaint"]) {
                $module_id = complaint::module_name($get_vars["complaint"]);
            }
            // check dependencies
            if ($exitinfo = module::missing_dependencies($module_id)) {
                return print($exitinfo);
            }
            // if not errors go on...
            // use _consult_ as prefix for any module interfacing with consult object
            if (class_exists($module_id)) {
                $eval_string = $module_id."::_consult_".$module_id."(\$menu_id,\$post_vars,\$get_vars,\$validuser,\$isadmin)".";";
                eval("$eval_string");
            }
        }

    }

    function _patientmodules() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        if ($exitinfo = module::missing_dependencies($get_vars["module"])) {
            return print($exitinfo);
        }
        // if not errors go on...
        // use _patient_ as prefix for any module interfacing with patient object
        if ($get_vars["module"]) {
            $eval_string = $get_vars["module"]."::_patient_".$get_vars["module"]."(\$menu_id,\$post_vars,\$get_vars,\$validuser,\$isadmin)".";";
            eval("$eval_string");
        } else {
            print "<b>Select profile to run.</b>";
        }


    }

    function _consult() {
    //
    // main consult file
    // executes with menu choice "Today's Patients"
    //

        static $patient;
        static $notes;
        static $lab;

        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        $wtforage = wtforage::wtforage();
        if (!isset($patient)) {
            $patient = new patient;
            $notes = new notes;
            $lab = new lab;
        }
        // always check dependencies
        if ($exitinfo = $this->missing_dependencies('healthcenter')) {
            return print($exitinfo);
        }
        if ($get_vars["patient_id"] && $get_vars["consult_id"]) {
            print "<table>";
            print "<tr valign='top'><td>";
            $this->patient_info($menu_id, $post_vars, $get_vars);
            print "</td></tr>";
            print "</table>";
        } else {
            if ($post_vars["submitpatient"]) {
                // processes form_patient
                $patient->process_patient($menu_id, $post_vars, $get_vars);
                $this->process_consult($menu_id, $post_vars, $get_vars);
                header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]);
            }
            if ($post_vars["submitconsult"]) {
                // confirms consult for found patients
                $this->process_consult($menu_id, $post_vars, $get_vars);
            }
            if ($post_vars["submitsearch"]) {
                // lists down search results for patient
                $patient->process_search($menu_id, $post_vars, $get_vars);
            }
            print "<table width='600'>";
            if ($get_vars["consult_id"]) {
                // if consult is selected from list of patients
                // display detailed patient information
                if ($post_vars["endconsult"]) {
                    $this->end_consult($menu_id, $post_vars, $get_vars);
                }
                print "<tr valign='top'><td colspan='2'>";
                $this->patient_info($menu_id, $post_vars, $get_vars);
                print "</td></tr>";
                print "<tr valign='top'><td colspan='2'>";
                $this->patient_menu($menu_id, $post_vars, $get_vars);
                if ($get_vars["ptmenu"]=="MODULES") {
                    // these are submenus associated with patient groups and complaints
                    print "<table cellpadding='1'>";
                    print "<tr><td>";
                    ptgroup::menu_modules($menu_id, $post_vars, $get_vars);
                    print "</td></tr><tr><td>";
                    complaint::menu_modules($menu_id, $post_vars, $get_vars);
                    print "</td></tr>";
                    print "</table>";
                }
                if ($get_vars["ptmenu"]=="PROFILES") {
                    print "<table cellpadding='1'>";
                    print "<tr><td>";
                    $patient->menu_modules($menu_id, $post_vars, $get_vars);
                    switch ($get_vars["ptmenu"]) {
                    case "PROFILES":
                        $this->_patientmodules($menu_id, $post_vars, $get_vars);
                        break;
                    }
                    print "</td></tr>";
                    print "</table>";
                }
                print "</td></tr>";
                print "<tr valign='top'><td>";
                // column 1
                switch ($get_vars["ptmenu"]) {
                case "APPTS":
                    calendar::_calendar($menu_id, $post_vars, $get_vars);
                    break;
                case "LABS":
                    if ($post_vars["submitlab"]) {
                        $lab->process_send_request($menu_id, $post_vars, $get_vars);
                    }
                    $lab->form_send_request($menu_id, $post_vars, $get_vars);
                    break;
                case "DETAILS":
                    if ($get_vars["module"]) {
                        $module_method = $get_vars["module"]."::_consult_".$get_vars["module"]."(\$menu_id, \$post_vars, \$get_vars);";
                        if (class_exists($get_vars["module"])) {
                            eval("$module_method");
                        }
                    } else {
                        if ($post_vars["submitdetails"]) {
                            $this->process_details($menu_id, $post_vars, $get_vars);
                        }
                        $this->form_visitdetails($menu_id, $post_vars, $get_vars);
                    }
                    break;
                case "VITALS":
                    //$this->show_vitalsigns($menu_id, $post_vars, $get_vars);
                    if ($post_vars["submitvitals"]) {
                        $this->process_vitalsigns($menu_id, $post_vars, $get_vars, $_SESSION["userid"]);
                    }
                    $this->form_vitalsigns($menu_id, $post_vars, $get_vars);
                    break;
                case "NOTES":
                    $notes->form_notes($menu_id, $post_vars, $get_vars);
                    break;
                case "MODULES":
                    $this->_consultmodules($menu_id, $post_vars, $get_vars);
                    break;
                }
                print "</td><td>";
                // column 2
                switch ($get_vars["ptmenu"]) {
                case "LABS":
                    // lab requests for this consult
                    // flag if done
                    $lab->display_requests($menu_id, $post_vars, $get_vars);
                    break;
                case "VITALS":
                    $this->display_vitals($menu_id, $post_vars, $get_vars);
                    break;
                case "DETAILS":
                    if ($get_vars["module"]) {
                        $module_method = $get_vars["module"]."::_details_".$get_vars["module"]."(\$menu_id, \$post_vars, \$get_vars);";
                        if (class_exists($get_vars["module"])) {
                            eval("$module_method");
                        }
                    } else {
                        $this->show_visitdetails($menu_id, $post_vars, $get_vars);
                        $this->display_consults($menu_id, $post_vars, $get_vars);
                    }
                    break;
                case "NOTES":
                    $this->show_visitdetails($menu_id, $post_vars, $get_vars);
                    break;
                }
                print "</td></tr>";
                print "<tr valign='top'><td colspan='2'>";
                // display all patients confirmed with consults
                $this->consult_info($menu_id, $post_vars, $get_vars);
                print "</td></tr>";
            } else {
                print "<tr valign='top'><td colspan='2'>";
                // display all patients confirmed with consults
                print "<table>";
                print "<tr><td>";
                $this->consult_info($menu_id, $post_vars, $get_vars);
                print "</td></tr>";
                print "<tr><td>";
                $patient->patient_info($menu_id, $post_vars, $get_vars);
                print "</td></tr>";
                print "</table>";
                print "</td></tr>";
                print "<tr valign='top'><td>";
                $patient->newsearch($menu_id, $post_vars, $get_vars);
                print "</td><td>";
                $patient->form_patient($menu_id, $post_vars, $get_vars);
                print "</td></tr>";
            }
            print "</table>";
        }
    }

    function end_consult() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        $sql = "update m_consult set consult_end = sysdate() where consult_id = '".$post_vars["consult_id"]."'";
        if ($result = mysql_query($sql)) {
            header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]);
        }
    }


    function display_vitals() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        print "<b>".FTITLE_VITAL_SIGNS_RECORD."</b><br/>";
        $sql = "select consult_id, vitals_timestamp, date_format(vitals_timestamp, '%a %d %b %Y, %h:%i%p') ".
               "from m_consult_vitals where consult_id = '".$get_vars["consult_id"]."'";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                while (list($cid, $ts, $date) = mysql_fetch_array($result)) {
                    print "<img src='../images/arrow_redwhite.gif' border='0'/> $date <a href='".$_SESSION["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=VITALS&timestamp=$ts'><img src='../images/view.png' border='0'/></a><br/>";
                    if ($get_vars["timestamp"]==$ts) {
                        $this->vitals_detail($menu_id, $post_vars, $get_vars);
                    }
                }
            } else {
                print "<font color='red'>none</font><br/>";
            }
        }
    }

    function vitals_detail() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        $sql = "select user_id, vitals_weight, vitals_temp, vitals_systolic, vitals_diastolic, vitals_heartrate, vitals_resprate ".
               "from m_consult_vitals where consult_id = '".$get_vars["consult_id"]."' and vitals_timestamp = '".$get_vars["timestamp"]."'";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                list($uid, $wt, $temp, $syst, $diast, $hrate, $rrate) = mysql_fetch_array($result);
                print "<table width='250' style='border: 1px dotted black'><tr><td colspan='2'>";
                print "Taken by: ".user::get_username($uid)."<br/>";
                print "<td></tr>";
                print "<tr valign='top'><td>";
                print "BP: $syst/$diast<br/>";
                print "HR: $hrate<br/>";
                print "RR: $rrate<br/>";
                print "</td><td>";
                print "Weight (kg): $wt<br/>";
                print "Temp deg C: $temp<br/>";
                print "</td></tr></table>";
            }
        }
    }

    function process_vitalsigns() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        switch($post_vars["submitvitals"]) {
        case "Save Vital Signs":
            if ($post_vars["bloodpressure"]) {
                list($systolic, $diastolic) = explode("/", $post_vars["bloodpressure"]);
            }
            $sql = "insert into m_consult_vitals (consult_id, user_id, vitals_weight, vitals_temp, vitals_systolic, vitals_diastolic, vitals_heartrate, vitals_resprate) ".
                   "values ('".$get_vars["consult_id"]."', '".$_SESSION["userid"]."', '".$post_vars["bodyweight"]."', '".$post_vars["bodytemp"]."', '$systolic', '$diastolic', '".$post_vars["heartrate"]."', '".$post_vars["resprate"]."')";
            if ($result = mysql_query($sql) or die(mysql_error())) {
                header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=VITALS");
            }
            break;
        }
    }

    function form_vitalsigns() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        print "<table width='300'>";
        print "<form action = '".$_SERVER["SELF"]."?page=".$get_vars["page"]."&menu_id=$menu_id&consult_id=".$get_vars["consult_id"]."&ptmenu=VITALS' name='form_vitalsigns' method='post'>";
        print "<tr valign='top'><td>";
        print "<b>".INSTR_CORRECT_VALUES."</b><br/><br/>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_BLOODPRESSURE."</span><br> ";
        print "<input type='text' class='textbox' size='10' maxlength='7' name='bloodpressure' value='".($anes_eval["eval_bloodpressure"]?$anes_eval["eval_bloodpressure"]:$post_vars["bloodpressure"])."' style='border: 1px solid #000000'><br>";
        print "<small>Example: 100/90, 160/100</small><br/>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_HEARTRATE."</span><br> ";
        print "<input type='text' class='textbox' size='10' maxlength='7' name='heartrate' value='".($anes_eval["eval_heartrate"]?$anes_eval["eval_heartrate"]:$post_vars["heartrate"])."' style='border: 1px solid #000000'><br>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_RESPRATE."</span><br> ";
        print "<input type='text' class='textbox' size='10' maxlength='7' name='resprate' value='".($anes_eval["eval_resprate"]?$anes_eval["eval_resprate"]:$post_vars["resprate"])."' style='border: 1px solid #000000'><br>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_WEIGHT."</span><br> ";
        print "<input type='text' class='textbox' size='10' maxlength='7' name='bodyweight' value='".($anes_eval["eval_weight"]?$anes_eval["eval_weight"]:$post_vars["bodyweight"])."' style='border: 1px solid #000000'><br>";
        print "</td></tr>";

        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_BODYTEMP."</span><br> ";
        print "<input type='text' class='textbox' size='10' maxlength='7' name='bodytemp' value='".($anes_eval["eval_temp"]?$anes_eval["eval_temp"]:$post_vars["bodytemp"])."' style='border: 1px solid #000000'><br>";
        print "</td></tr>";
        print "<tr><td>";
        if ($_SESSION["priv_add"]) {
            print "<br><input type='submit' value = 'Save Vital Signs' class='textbox' name='submitvitals' style='border: 1px solid #000000'><br>";
        }
        print "</td></tr>";
        print "</form>";
        print "</table><br>";
    }

    function display_consults() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        print "<b>".FTITLE_PREVIOUS_VISITS."</b><br/>";
        $patient_id = $this->get_patient_id($get_vars["consult_id"]);
        $sql = "select consult_id, date_format(consult_timestamp, '%a %d %b %Y, %h:%i%p') ".
               "from m_consult where patient_id = $patient_id order by consult_timestamp desc";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                while (list($cid, $date) = mysql_fetch_array($result)) {
                    print "<img src='../images/arrow_redwhite.gif' border='0'/> $date <a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=$cid&ptmenu=DETAILS'>".($get_vars["consult_id"]<>$cid?"<img src='../images/view.png' border='0'/>":"")."</a><br/>";
                }
            }
        }
    }

    function patient_menu() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        print "<table width='600' cellpadding='2' bgcolor='#CCCC99' cellspacing='1' style='border: 2px solid black'><tr>";
        print "<td><a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=DETAILS' class='ptmenu'>".($get_vars["ptmenu"]=="DETAILS"?"<b>".MENU_VISIT_DETAILS."</b>":MENU_VISIT_DETAILS)."</a></td>";
        print "<td><a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=APPTS' class='ptmenu'>".($get_vars["ptmenu"]=="APPTS"?"<b>".MENU_APPTS."</b>":MENU_APPTS)."</a></td>";
        print "<td><a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=VITALS' class='ptmenu'>".($get_vars["ptmenu"]=="VITALS"?"<b>".MENU_VITAL_SIGNS."</b>":MENU_VITAL_SIGNS)."</td>";
        print "<td><a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=LABS' class='ptmenu'>".($get_vars["ptmenu"]=="LABS"?"<b>".MENU_LABS."</b>":MENU_LABS)."</td>";
        print "<td><a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=NOTES' class='ptmenu'>".($get_vars["ptmenu"]=="NOTES"?"<b>".MENU_NOTES."</b>":MENU_NOTES)."</td>";
        print "<td><a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=PROFILES' class='ptmenu'>".($get_vars["ptmenu"]=="PROFILES"?"<b>".MENU_PROFILES."</b>":MENU_PROFILES)."</td>";
        print "<td><a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=MODULES' class='ptmenu'>".($get_vars["ptmenu"]=="MODULES"?"<b>".MENU_MODULES."</b>":MENU_MODULES)."</td>";
        print "</tr></table>";
    }

    function patient_info() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        if ($get_vars["consult_id"]) {
            $sql = "select p.patient_id, p.patient_lastname, p.patient_firstname, round((to_days(now())-to_days(p.patient_dob))/365 , 1) computed_age, p.patient_gender, p.patient_dob, c.consult_end ".
                   "from m_patient p, m_consult c ".
                   "where c.patient_id = p.patient_id and c.consult_id = '".$get_vars["consult_id"]."'";
            if ($result = mysql_query($sql)) {
                if (mysql_num_rows($result)) {
                    $ptinfo = mysql_fetch_array($result);
                }
            }
        }
        print "<table width='600' cellpadding='2' cellspacing='0' style='border: 2px solid black'>";
        print "<form method='post' action='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."'>";
        print "<tr><td colspan='2' bgcolor='#FFFFCC'>";
        print "<span class='library'>".strtoupper($ptinfo["patient_lastname"].", ".$ptinfo["patient_firstname"])."</span> <br/>";
        print LBL_FAMILY_NUMBER." <b>".family::search_family($ptinfo["patient_id"])."</b>&nbsp;&nbsp;&nbsp;"."AGE: <b>".$ptinfo["computed_age"]."/".$ptinfo["patient_gender"]."</b>&nbsp;&nbsp;&nbsp; BIRTHDATE: <b>".$ptinfo["patient_dob"]."</b><br/>";
        print "</td></tr>";
        print "<tr valign='top' bgcolor='#FFFF99'><td>";
        print LBL_TOTAL_VISITS."<b>".$this->get_totalvisits($ptinfo["patient_id"])."</b><br/>";
        print LBL_LAST_VISIT." <b>".$this->get_lastvisit($ptinfo["patient_id"])."</b><br/>";
        print "</td><td>&nbsp;";
        print "</td></tr>";
        print "<tr><td colspan='2' bgcolor='#FFFF66'>";
        print "<input type='hidden' name='consult_id' value='".$get_vars["consult_id"]."'/>";
        print LBL_ELAPSED_TIME." <b>".$this->get_elapsedtime($get_vars["consult_id"])."</b> &nbsp;&nbsp;";
        if ($ptinfo["consult_end"]=="00000000000000") {
            print "<input type='submit' name='endconsult' class='tiny' value='".BTN_END_CONSULT."' style='border: 1px solid black; background-color: #FFCC33'/><br/>";
        }
        print "</td></tr>";
        print "</form>";
        print "</table>";
    }

    function get_patient_id() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $consult_id = $arg_list[0];
        }
        $sql = "select patient_id from m_consult where consult_id = '$consult_id'";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                list($patient_id) = mysql_fetch_array($result);
                return $patient_id;
            }
        }
    }

    function get_totalvisits() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $patient_id = $arg_list[0];
        }
        $sql = "select count(consult_id) from m_consult where patient_id = '$patient_id'";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                list($count) = mysql_fetch_array($result);
                return $count;
            }
        }
    }

    function get_lastvisit() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $patient_id = $arg_list[0];
        }
        $sql = "select date_format(consult_timestamp, '%a %d %b %Y, %h:%i%p') from m_consult where patient_id = '$patient_id'";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                list($date) = mysql_fetch_array($result);
                return $date;
            }
        }
    }

    function show_visitdetails() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        print "<b>".FTITLE_PATIENT_GROUP."</b><br/>";
        if ($get_vars["deletets"] && $get_vars["deletegroup"]) {
            $sql_delete = "delete from m_consult_ptgroup where consult_id = '".$get_vars["consult_id"]."' and ptgroup_timestamp = '".$get_vars["deletets"]."' and ptgroup_id = '".$get_vars["deletegroup"]."'";
            $result_delete = mysql_query($sql_delete);
        }
        $sql_ptgroup = "select g.ptgroup_name, g.ptgroup_module, c.ptgroup_timestamp, c.ptgroup_id from m_consult_ptgroup c, m_lib_ptgroup g ".
                       "where g.ptgroup_id = c.ptgroup_id and c.consult_id = '".$get_vars["consult_id"]."'";
        if ($result = mysql_query($sql_ptgroup)) {
            if (mysql_num_rows($result)) {
                while (list($name, $mod, $ts, $grp) = mysql_fetch_array($result)) {
                    print "<img src='../images/arrow_redwhite.gif' border='0'/> <a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=$mod'>$name</a> ";
                    print "<a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=DETAILS&deletets=$ts&deletegroup=$grp'><img src='../images/delete.png' border='0'/></a><br/>";
                }
            } else {
                print "<font color='red'>none</font><br/>";
            }
        }
        print "<br/>";
        print "<b>".FTITLE_CONSULT_COMPLAINTS."</b><br/>";
        if ($get_vars["deletets"] && $get_vars["deletecomplaint"]) {
            $sql_delete = "delete from m_consult_complaint where consult_id = '".$get_vars["consult_id"]."' and ptgroup_timestamp = '".$get_vars["deletets"]."' and complaint_id = '".$get_vars["deletecomplaint"]."'";
            $result_delete = mysql_query($sql_delete);
        }
        $sql_complaint = "select l.complaint_name, l.complaint_module, c.complaint_timestamp, c.complaint_id from m_consult_complaint c, m_lib_complaint l ".
                         "where l.complaint_id = c.complaint_id and c.consult_id = '".$get_vars["consult_id"]."'";
        if ($result = mysql_query($sql_complaint)) {
            if (mysql_num_rows($result)) {
                while (list($name, $mod, $ts, $comp) = mysql_fetch_array($result)) {
                    print "<img src='../images/arrow_redwhite.gif' border='0'/> <a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=".$get_vars["ptmenu"]."&module=$mod'>$name</a> ";
                    print "<a href='".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=".$get_vars["consult_id"]."&ptmenu=DETAILS&deletets=$ts&deletecomplaint=$comp'><img src='../images/delete.png' border='0'/></a><br/>";
                }
            } else {
                print "<font color='red'>none</font><br/>";
            }
        }
        print "<br/>";
    }

    function process_details() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        if ($post_vars["submitdetails"]) {
            if (count($post_vars["ptgroup"])>0) {
                // any ptgroup checked
                foreach($post_vars["ptgroup"] as $key=>$value) {
                    $sql = "insert into m_consult_ptgroup (ptgroup_id, consult_id, ptgroup_timestamp, user_id) ".
                           "values ('$value', '".$get_vars["consult_id"]."', sysdate(), '".$_SESSION["userid"]."')";
                    $result = mysql_query($sql);
                }
            }
            if (count($post_vars["complaintcat"])>0) {
                foreach($post_vars["complaintcat"] as $key=>$value) {
                    $sql = "insert into m_consult_complaint (complaint_id, consult_id, complaint_timestamp, user_id) ".
                           "values ('$value', '".$get_vars["consult_id"]."', sysdate(), '".$_SESSION["userid"]."')";
                    $result = mysql_query($sql);
                }
            }
        }
    }

    function form_visitdetails() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        $patient_id = $this->get_patient_id($get_vars["consult_id"]);
        $age = patient::get_age($patient_id);
        $gender = patient::get_gender($patient_id);
        print "<table width='300'>";
        print "<form action = '".$_SERVER["SELF"]."?page=CONSULTS&menu_id=$menu_id&consult_id=".$get_vars["consult_id"]."&ptmenu=DETAILS' name='form_patient' method='post'>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_PTGROUP."</span><br> ";
        print ptgroup::checkbox_ptgroup($age, $gender);
        print "<br>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_COMPLAINTCAT."</span><br> ";
        print complaint::checkbox_complaintcat($age, $gender);
        print "<br>";
        print "</td></tr>";
        /*
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_VISIT_TYPE."</span><br> ";
        print "<input type='radio' name='visit_type' value='1'/> First visit<br/>";
        print "<input type='radio' name='visit_type' value='2'/> Follow-up visit<br/>";
        print "</td></tr>";
        */
        print "<tr><td>";
        print "<br><input type='submit' value = '".BTN_SAVE_DETAILS."' class='textbox' name='submitdetails' style='border: 1px solid #000000'><br>";
        print "</td></tr>";
        print "</form>";
        print "</table><br>";
    }

    function get_elapsedtime() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $consult_id = $arg_list[0];
        }
        $sql = "select date_format(c.consult_timestamp, '%b %d %Y, %h:%i %p'), ".
               "(unix_timestamp()-unix_timestamp(c.consult_timestamp))/3600 elapsed from m_consult c ".
               "where c.consult_id = $consult_id";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                list($date, $elapsed) = mysql_fetch_array($result);
                return "$date $elapsed"."H elapsed";
            }
        }
    }

    function consult_info() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        $sql = "select c.consult_id, p.patient_id, p.patient_lastname, p.patient_firstname ".
               "from m_consult c, m_patient p where c.patient_id = p.patient_id ".
               "and consult_end = '00000000000000' order by c.consult_timestamp desc";
        if ($result = mysql_query($sql)) {
            print "<table width=600 bgcolor='#FFFFFF' cellpadding='3' cellspacing='0' style='border: 2px solid black'>";
            print "<tr><td>";
            print "<span class='patient'>CONSULTS TODAY</span><br>";
            if (mysql_num_rows($result)) {
                $i=0;
                while (list($cid, $pid, $plast, $pfirst) = mysql_fetch_array($result)) {
                    $consult_array[$i] = "<a href='".$_SERVER["PHP_SELF"]."?page=CONSULTS&menu_id=$menu_id&consult_id=$cid&ptmenu=DETAILS'><b>$plast, $pfirst</b></a> [$cid]";
                    $i++;
                }
                print $this->columnize_list($consult_array);
            } else {
                print "<font color='red'>No consults available.</font>";
            }
            print "</td></tr>";
            print "</table>";
        }
    }

    function process_consult() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        $sql = "insert into m_consult (patient_id, user_id, healthcenter_id) ".
               "values ('".$post_vars["consult_id"]."', '".$_SESSION["userid"]."', '".$_SESSION["datanode"]["code"]."')";

        if ($result = mysql_query($sql)) {
            $insert_id = mysql_insert_id();
            header("location: ".$_SERVER["PHP_SELF"]."?page=".$get_vars["page"]."&menu_id=".$get_vars["menu_id"]."&consult_id=$insert_id&ptmenu=DETAILS");
        }

    }

    function _consult_stats() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            //print_r($arg_list);
        }
        print "<table>";
        print "<tr><td>";
        // column 1
        print "TOTAL PATIENTS: <br/>";
        print "&nbsp;&nbsp; x males<br/>";
        print "&nbsp;&nbsp; x females<br/>";
        print "<br/>";
        print "TOTAL CONSULTS: ".$this->total_consults()."<br/>";
        print "</td><td>";
        // column 2
        print "</td></tr>";
        print "</table>";
    }

    function total_consults() {
        $sql = "select count(consult_id) from m_consult";
        if ($result = mysql_query($sql)) {
            if (mysql_num_rows($result)) {
                list($count) = mysql_fetch_array($result);
                return $count;
            }
        }
    }

// end of class
}
?>
